package com.lag.demo.controller;

import com.lag.demo.mapper.ArticleMapper;
import com.lag.demo.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author June
 * @since 2021年01月
 */
@Controller
public class ArticleController {

    @Autowired
    private ArticleMapper articleMapper;

    @RequestMapping("/index")
    public String index(Model model, @RequestParam(defaultValue = "1") int page) {
        int offset = (page - 1) * 10;
        List<Article> articleList = articleMapper.selectArticleByPage(offset, 10);
        int total = articleMapper.countArticle();
        model.addAttribute("articleList", articleList);
        model.addAttribute("total", total);
        model.addAttribute("currentPage", page);
        return "client/index";
    }

}
